package edu.pku.sei.modeler.uml.commands.umlclass;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.Dependencies.Dependency;
import edu.pku.sei.modeler.model.uml.Kernel.NamedElement;
import edu.pku.sei.modeler.uml.commands.ConnectionModelDeleteCommand;

public class UMLDependencyDeleteCommand extends ConnectionModelDeleteCommand {

	public UMLDependencyDeleteCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel, MetaModelElement targetModel) {
		super(connectionModel, sourceModel, targetModel);
	}

	@Override
	public void execute() {
		MetaModelElement sourceModelElement = this.sourceModel;
		if (!(sourceModelElement instanceof NamedElement)) {
			return;
		}

		NamedElement sourceElement = (NamedElement) sourceModelElement;
		Dependency dependency = (Dependency) connectionModel;
		sourceElement.getSupplierDependency().remove(dependency);
		dependency.getClientDependency().remove(this.targetModel);

	}

	@Override
	public void undo() {
		MetaModelElement sourceModelElement = this.sourceModel;
		if (!(sourceModelElement instanceof NamedElement)) {
			return;
		}

		NamedElement sourceElement = (NamedElement) sourceModelElement;
		Dependency dependency = (Dependency) connectionModel;
		sourceElement.getSupplierDependency().add(dependency);
		// dependency.getSupplierDependency().add(sourceElement);
		dependency.getClientDependency().add(this.targetModel);
	}

}
